package org.base.common;


import java.util.HashMap;
import static org.base.common.ResponseCode.*;


public class R extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	
	public R() {
		this(SUCCESS);
	}
	
	public R(ResponseCode responseCode) {
		put("code", responseCode.getCode());
		put("msg", responseCode.getMsg());
	}
	
	public static R error() {
		return new R(SYSTERM_EXCEPTION);
	}
	
	public static R error(String msg) {
		return error(SYSTERM_EXCEPTION.getCode(), msg);
	}
	
	public static R error(int code, String msg) {
		R r = new R();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}
	
	public static R error(SysException e) {
		R r = new R();
		r.put("code", e.getCode());
		r.put("msg", e.getMsg());
		return r;
	}

	public static R ok(String msg) {
		R r = new R();
		r.put("msg", msg);
		return r;
	}
	
	public static R ok() {
		R r = new R();
		return r;
	}

	@Override
	public R put(String key, Object value) {
		super.put(key, value);
		return this;
	}
	
	public static R result(Object o) {
		R r = new R();
		r.put("result", o);
		return r;
	}
}
